<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>SFML - Simple and Fast Multimedia Library</title>
        <meta http-equiv="Content-Type" content="text/html;"/>
        <meta charset="utf-8"/>
        <!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
        <link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="dynsections.js"></script>
        <link rel="stylesheet" type="text/css" href="search/search.css" />
        <link rel="stylesheet" type="text/css" href="searchOverrides.css" />
        <script type="text/javascript" src="search/searchdata.js"></script>
        <script type="text/javascript" src="search/search.js"></script>
        <script type="text/javascript">
        /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
          $(document).ready(function() { init_search(); });
        /* @license-end */
        </script>
    </head>
    <body>
        <div id="banner-container">
            <div id="banner">
                <span id="sfml">SFML 2.6.1</span>
            </div>
        </div>
        <div id="content">
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>sf</b></li><li class="navelem"><a class="el" href="classsf_1_1UdpSocket.html">UdpSocket</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-types">Protected Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="classsf_1_1UdpSocket-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">sf::UdpSocket Class Reference<div class="ingroups"><a class="el" href="group__network.html">Network module</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Specialized socket using the UDP protocol.  
 <a href="classsf_1_1UdpSocket.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="UdpSocket_8hpp_source.html">SFML/Network/UdpSocket.hpp</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for sf::UdpSocket:</div>
<div class="dyncontent">
 <div class="center">
  <img src="classsf_1_1UdpSocket.png" usemap="#sf::UdpSocket_map" alt=""/>
  <map id="sf::UdpSocket_map" name="sf::UdpSocket_map">
<area href="classsf_1_1Socket.html" title="Base class for all the socket types." alt="sf::Socket" shape="rect" coords="0,56,105,80"/>
<area href="classsf_1_1NonCopyable.html" title="Utility class that makes any derived class non-copyable." alt="sf::NonCopyable" shape="rect" coords="0,0,105,24"/>
  </map>
</div></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-types" name="pub-types"></a>
Public Types</h2></td></tr>
<tr class="memitem:a8ad087820b1ae07267858212f3d0fac5"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom">{ <a class="el" href="classsf_1_1UdpSocket.html#a8ad087820b1ae07267858212f3d0fac5a728a7d33027bee0d65f70f964dd9c9eb">MaxDatagramSize</a> = 65507
 }</td></tr>
<tr class="separator:a8ad087820b1ae07267858212f3d0fac5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a51bf0fd51057b98a10fbb866246176dc"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> { <br />
&#160;&#160;<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90">Done</a>
, <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09">NotReady</a>
, <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706">Partial</a>
, <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1">Disconnected</a>
, <br />
&#160;&#160;<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d">Error</a>
<br />
 }</td></tr>
<tr class="memdesc:a51bf0fd51057b98a10fbb866246176dc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Status codes that may be returned by socket functions.  <a href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">More...</a><br /></td></tr>
<tr class="separator:a51bf0fd51057b98a10fbb866246176dc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom">{ <a class="el" href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19">AnyPort</a> = 0
 }</td></tr>
<tr class="memdesc:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="mdescLeft">&#160;</td><td class="mdescRight">Some special values used by sockets.  <a href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75">More...</a><br /></td></tr>
<tr class="separator:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:abb10725e26dee9d3a8165fe87ffb71bb"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#abb10725e26dee9d3a8165fe87ffb71bb">UdpSocket</a> ()</td></tr>
<tr class="memdesc:abb10725e26dee9d3a8165fe87ffb71bb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Default constructor.  <br /></td></tr>
<tr class="separator:abb10725e26dee9d3a8165fe87ffb71bb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5c03644b3da34bb763bce93e758c938e"><td class="memItemLeft" align="right" valign="top">unsigned short&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#a5c03644b3da34bb763bce93e758c938e">getLocalPort</a> () const</td></tr>
<tr class="memdesc:a5c03644b3da34bb763bce93e758c938e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the port to which the socket is bound locally.  <br /></td></tr>
<tr class="separator:a5c03644b3da34bb763bce93e758c938e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad764c3d06d90b4714dcc97a0d1647bcc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc">bind</a> (unsigned short port, const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;address=<a class="el" href="classsf_1_1IpAddress.html#a3dbc10b0dc6804cc69e29342f7406907">IpAddress::Any</a>)</td></tr>
<tr class="memdesc:ad764c3d06d90b4714dcc97a0d1647bcc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Bind the socket to a specific port.  <br /></td></tr>
<tr class="separator:ad764c3d06d90b4714dcc97a0d1647bcc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2c4abb8102a1bd31f51fcfe7f15427a3"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#a2c4abb8102a1bd31f51fcfe7f15427a3">unbind</a> ()</td></tr>
<tr class="memdesc:a2c4abb8102a1bd31f51fcfe7f15427a3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Unbind the socket from the local port to which it is bound.  <br /></td></tr>
<tr class="separator:a2c4abb8102a1bd31f51fcfe7f15427a3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a664ab8f26f37c21cc4de1b847c2efcca"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#a664ab8f26f37c21cc4de1b847c2efcca">send</a> (const void *data, std::size_t size, const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;remoteAddress, unsigned short remotePort)</td></tr>
<tr class="memdesc:a664ab8f26f37c21cc4de1b847c2efcca"><td class="mdescLeft">&#160;</td><td class="mdescRight">Send raw data to a remote peer.  <br /></td></tr>
<tr class="separator:a664ab8f26f37c21cc4de1b847c2efcca"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ade9ca0f7ed7919136917b0b997a9833a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#ade9ca0f7ed7919136917b0b997a9833a">receive</a> (void *data, std::size_t size, std::size_t &amp;received, <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;remoteAddress, unsigned short &amp;remotePort)</td></tr>
<tr class="memdesc:ade9ca0f7ed7919136917b0b997a9833a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Receive raw data from a remote peer.  <br /></td></tr>
<tr class="separator:ade9ca0f7ed7919136917b0b997a9833a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a48969a62c80d40fd74293a740798e435"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#a48969a62c80d40fd74293a740798e435">send</a> (<a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;packet, const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;remoteAddress, unsigned short remotePort)</td></tr>
<tr class="memdesc:a48969a62c80d40fd74293a740798e435"><td class="mdescLeft">&#160;</td><td class="mdescRight">Send a formatted packet of data to a remote peer.  <br /></td></tr>
<tr class="separator:a48969a62c80d40fd74293a740798e435"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:afdd5c655d00c96222d5b477fc057a22b"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1UdpSocket.html#afdd5c655d00c96222d5b477fc057a22b">receive</a> (<a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;packet, <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;remoteAddress, unsigned short &amp;remotePort)</td></tr>
<tr class="memdesc:afdd5c655d00c96222d5b477fc057a22b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Receive a formatted packet of data from a remote peer.  <br /></td></tr>
<tr class="separator:afdd5c655d00c96222d5b477fc057a22b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a165fc1423e281ea2714c70303d3a9782"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a165fc1423e281ea2714c70303d3a9782">setBlocking</a> (bool blocking)</td></tr>
<tr class="memdesc:a165fc1423e281ea2714c70303d3a9782"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set the blocking state of the socket.  <br /></td></tr>
<tr class="separator:a165fc1423e281ea2714c70303d3a9782"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#ab1ceca9ac114b8baeeda3b34a0aca468">isBlocking</a> () const</td></tr>
<tr class="memdesc:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="mdescLeft">&#160;</td><td class="mdescRight">Tell whether the socket is in blocking or non-blocking mode.  <br /></td></tr>
<tr class="separator:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pro-types" name="pro-types"></a>
Protected Types</h2></td></tr>
<tr class="memitem:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">Type</a> { <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214">Tcp</a>
, <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2">Udp</a>
 }</td></tr>
<tr class="memdesc:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Types of protocols that the socket can use.  <a href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">More...</a><br /></td></tr>
<tr class="separator:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pro-methods" name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:a675457784284ae2f5640bbbe16729393"><td class="memItemLeft" align="right" valign="top">SocketHandle&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a675457784284ae2f5640bbbe16729393">getHandle</a> () const</td></tr>
<tr class="memdesc:a675457784284ae2f5640bbbe16729393"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the internal handle of the socket.  <br /></td></tr>
<tr class="separator:a675457784284ae2f5640bbbe16729393"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#aafbe140f4b1921e0d19e88cf7a61dcbc">create</a> ()</td></tr>
<tr class="memdesc:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create the internal representation of the socket.  <br /></td></tr>
<tr class="separator:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#af1dd898f7aa3ead7ff7b2d1c20e97781">create</a> (SocketHandle handle)</td></tr>
<tr class="memdesc:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create the internal representation of the socket from a socket handle.  <br /></td></tr>
<tr class="separator:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a71f2f5c2aa99e01cafe824fee4c573be"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a71f2f5c2aa99e01cafe824fee4c573be">close</a> ()</td></tr>
<tr class="memdesc:a71f2f5c2aa99e01cafe824fee4c573be"><td class="mdescLeft">&#160;</td><td class="mdescRight">Close the socket gracefully.  <br /></td></tr>
<tr class="separator:a71f2f5c2aa99e01cafe824fee4c573be"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Specialized socket using the UDP protocol. </p>
<p>A UDP socket is a connectionless socket.</p>
<p>Instead of connecting once to a remote host, like TCP sockets, it can send to and receive from any host at any time.</p>
<p>It is a datagram protocol: bounded blocks of data (datagrams) are transfered over the network rather than a continuous stream of data (TCP). Therefore, one call to send will always match one call to receive (if the datagram is not lost), with the same data that was sent.</p>
<p>The UDP protocol is lightweight but unreliable. Unreliable means that datagrams may be duplicated, be lost or arrive reordered. However, if a datagram arrives, its data is guaranteed to be valid.</p>
<p>UDP is generally used for real-time communication (audio or video streaming, real-time games, etc.) where speed is crucial and lost data doesn't matter much.</p>
<p>Sending and receiving data can use either the low-level or the high-level functions. The low-level functions process a raw sequence of bytes, whereas the high-level interface uses packets (see <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">sf::Packet</a>), which are easier to use and provide more safety regarding the data that is exchanged. You can look at the <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">sf::Packet</a> class to get more details about how they work.</p>
<p>It is important to note that <a class="el" href="classsf_1_1UdpSocket.html" title="Specialized socket using the UDP protocol.">UdpSocket</a> is unable to send datagrams bigger than MaxDatagramSize. In this case, it returns an error and doesn't send anything. This applies to both raw data and packets. Indeed, even packets are unable to split and recompose data, due to the unreliability of the protocol (dropped, mixed or duplicated datagrams may lead to a big mess when trying to recompose a packet).</p>
<p>If the socket is bound to a port, it is automatically unbound from it when the socket is destroyed. However, you can unbind the socket explicitly with the Unbind function if necessary, to stop receiving messages or make the port available for other sockets.</p>
<p>Usage example: </p><div class="fragment"><div class="line"><span class="comment">// ----- The client -----</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create a socket and bind it to the port 55001</span></div>
<div class="line"><a class="code hl_class" href="classsf_1_1UdpSocket.html">sf::UdpSocket</a> socket;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc">bind</a>(55001);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Send a message to 192.168.1.50 on port 55002</span></div>
<div class="line">std::string message = <span class="stringliteral">&quot;Hi, I am &quot;</span> + <a class="code hl_function" href="classsf_1_1IpAddress.html#a4c31622ad87edca48adbb8e8ed00ee4a">sf::IpAddress::getLocalAddress</a>().<a class="code hl_function" href="classsf_1_1IpAddress.html#a88507954142d7fc2176cce7f36422340">toString</a>();</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1UdpSocket.html#a664ab8f26f37c21cc4de1b847c2efcca">send</a>(message.c_str(), message.size() + 1, <span class="stringliteral">&quot;192.168.1.50&quot;</span>, 55002);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Receive an answer (most likely from 192.168.1.50, but could be anyone else)</span></div>
<div class="line"><span class="keywordtype">char</span> buffer[1024];</div>
<div class="line">std::size_t received = 0;</div>
<div class="line"><a class="code hl_class" href="classsf_1_1IpAddress.html">sf::IpAddress</a> sender;</div>
<div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> port;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1UdpSocket.html#ade9ca0f7ed7919136917b0b997a9833a">receive</a>(buffer, <span class="keyword">sizeof</span>(buffer), received, sender, port);</div>
<div class="line">std::cout &lt;&lt; sender.ToString() &lt;&lt; <span class="stringliteral">&quot; said: &quot;</span> &lt;&lt; buffer &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// ----- The server -----</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create a socket and bind it to the port 55002</span></div>
<div class="line"><a class="code hl_class" href="classsf_1_1UdpSocket.html">sf::UdpSocket</a> socket;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc">bind</a>(55002);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Receive a message from anyone</span></div>
<div class="line"><span class="keywordtype">char</span> buffer[1024];</div>
<div class="line">std::size_t received = 0;</div>
<div class="line"><a class="code hl_class" href="classsf_1_1IpAddress.html">sf::IpAddress</a> sender;</div>
<div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> port;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1UdpSocket.html#ade9ca0f7ed7919136917b0b997a9833a">receive</a>(buffer, <span class="keyword">sizeof</span>(buffer), received, sender, port);</div>
<div class="line">std::cout &lt;&lt; sender.ToString() &lt;&lt; <span class="stringliteral">&quot; said: &quot;</span> &lt;&lt; buffer &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Send an answer</span></div>
<div class="line">std::string message = <span class="stringliteral">&quot;Welcome &quot;</span> + sender.<a class="code hl_function" href="classsf_1_1IpAddress.html#a88507954142d7fc2176cce7f36422340">toString</a>();</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1UdpSocket.html#a664ab8f26f37c21cc4de1b847c2efcca">send</a>(message.c_str(), message.size() + 1, sender, port);</div>
<div class="ttc" id="aclasssf_1_1IpAddress_html"><div class="ttname"><a href="classsf_1_1IpAddress.html">sf::IpAddress</a></div><div class="ttdoc">Encapsulate an IPv4 network address.</div><div class="ttdef"><b>Definition</b> <a href="IpAddress_8hpp_source.html#l00044">IpAddress.hpp:45</a></div></div>
<div class="ttc" id="aclasssf_1_1IpAddress_html_a4c31622ad87edca48adbb8e8ed00ee4a"><div class="ttname"><a href="classsf_1_1IpAddress.html#a4c31622ad87edca48adbb8e8ed00ee4a">sf::IpAddress::getLocalAddress</a></div><div class="ttdeci">static IpAddress getLocalAddress()</div><div class="ttdoc">Get the computer's local address.</div></div>
<div class="ttc" id="aclasssf_1_1IpAddress_html_a88507954142d7fc2176cce7f36422340"><div class="ttname"><a href="classsf_1_1IpAddress.html#a88507954142d7fc2176cce7f36422340">sf::IpAddress::toString</a></div><div class="ttdeci">std::string toString() const</div><div class="ttdoc">Get a string representation of the address.</div></div>
<div class="ttc" id="aclasssf_1_1UdpSocket_html"><div class="ttname"><a href="classsf_1_1UdpSocket.html">sf::UdpSocket</a></div><div class="ttdoc">Specialized socket using the UDP protocol.</div><div class="ttdef"><b>Definition</b> <a href="UdpSocket_8hpp_source.html#l00045">UdpSocket.hpp:46</a></div></div>
<div class="ttc" id="aclasssf_1_1UdpSocket_html_a664ab8f26f37c21cc4de1b847c2efcca"><div class="ttname"><a href="classsf_1_1UdpSocket.html#a664ab8f26f37c21cc4de1b847c2efcca">sf::UdpSocket::send</a></div><div class="ttdeci">Status send(const void *data, std::size_t size, const IpAddress &amp;remoteAddress, unsigned short remotePort)</div><div class="ttdoc">Send raw data to a remote peer.</div></div>
<div class="ttc" id="aclasssf_1_1UdpSocket_html_ad764c3d06d90b4714dcc97a0d1647bcc"><div class="ttname"><a href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc">sf::UdpSocket::bind</a></div><div class="ttdeci">Status bind(unsigned short port, const IpAddress &amp;address=IpAddress::Any)</div><div class="ttdoc">Bind the socket to a specific port.</div></div>
<div class="ttc" id="aclasssf_1_1UdpSocket_html_ade9ca0f7ed7919136917b0b997a9833a"><div class="ttname"><a href="classsf_1_1UdpSocket.html#ade9ca0f7ed7919136917b0b997a9833a">sf::UdpSocket::receive</a></div><div class="ttdeci">Status receive(void *data, std::size_t size, std::size_t &amp;received, IpAddress &amp;remoteAddress, unsigned short &amp;remotePort)</div><div class="ttdoc">Receive raw data from a remote peer.</div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html" title="Base class for all the socket types.">sf::Socket</a>, <a class="el" href="classsf_1_1TcpSocket.html" title="Specialized socket using the TCP protocol.">sf::TcpSocket</a>, <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">sf::Packet</a> </dd></dl>

<p class="definition">Definition at line <a class="el" href="UdpSocket_8hpp_source.html#l00045">45</a> of file <a class="el" href="UdpSocket_8hpp_source.html">UdpSocket.hpp</a>.</p>
</div><h2 class="groupheader">Member Enumeration Documentation</h2>
<a id="aa3e6c984bcb81a35234dcc9cc8369d75" name="aa3e6c984bcb81a35234dcc9cc8369d75"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa3e6c984bcb81a35234dcc9cc8369d75">&#9670;&#160;</a></span>anonymous enum</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">anonymous enum</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Some special values used by sockets. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19" name="aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19"></a>AnyPort&#160;</td><td class="fielddoc"><p>Special value that tells the system to pick any available port. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00066">66</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>

</div>
</div>
<a id="a8ad087820b1ae07267858212f3d0fac5" name="a8ad087820b1ae07267858212f3d0fac5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8ad087820b1ae07267858212f3d0fac5">&#9670;&#160;</a></span>anonymous enum</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">anonymous enum</td>
        </tr>
      </table>
</div><div class="memdoc">
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a8ad087820b1ae07267858212f3d0fac5a728a7d33027bee0d65f70f964dd9c9eb" name="a8ad087820b1ae07267858212f3d0fac5a728a7d33027bee0d65f70f964dd9c9eb"></a>MaxDatagramSize&#160;</td><td class="fielddoc"><p>The maximum number of bytes that can be sent in a single UDP datagram. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="UdpSocket_8hpp_source.html#l00052">52</a> of file <a class="el" href="UdpSocket_8hpp_source.html">UdpSocket.hpp</a>.</p>

</div>
</div>
<a id="a51bf0fd51057b98a10fbb866246176dc" name="a51bf0fd51057b98a10fbb866246176dc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a51bf0fd51057b98a10fbb866246176dc">&#9670;&#160;</a></span>Status</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">sf::Socket::Status</a></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Status codes that may be returned by socket functions. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90" name="a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90"></a>Done&#160;</td><td class="fielddoc"><p>The socket has sent / received the data. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09" name="a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09"></a>NotReady&#160;</td><td class="fielddoc"><p>The socket is not ready to send / receive data yet. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706" name="a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706"></a>Partial&#160;</td><td class="fielddoc"><p>The socket sent a part of the data. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1" name="a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1"></a>Disconnected&#160;</td><td class="fielddoc"><p>The TCP socket has been disconnected. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d" name="a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d"></a>Error&#160;</td><td class="fielddoc"><p>An unexpected error happened. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00053">53</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>

</div>
</div>
<a id="a5d3ff44e56e68f02816bb0fabc34adf8" name="a5d3ff44e56e68f02816bb0fabc34adf8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5d3ff44e56e68f02816bb0fabc34adf8">&#9670;&#160;</a></span>Type</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">sf::Socket::Type</a></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Types of protocols that the socket can use. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214" name="a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214"></a>Tcp&#160;</td><td class="fielddoc"><p>TCP protocol. </p>
</td></tr>
<tr><td class="fieldname"><a id="a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2" name="a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2"></a>Udp&#160;</td><td class="fielddoc"><p>UDP protocol. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00114">114</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>

</div>
</div>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="abb10725e26dee9d3a8165fe87ffb71bb" name="abb10725e26dee9d3a8165fe87ffb71bb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#abb10725e26dee9d3a8165fe87ffb71bb">&#9670;&#160;</a></span>UdpSocket()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">sf::UdpSocket::UdpSocket </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Default constructor. </p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="ad764c3d06d90b4714dcc97a0d1647bcc" name="ad764c3d06d90b4714dcc97a0d1647bcc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad764c3d06d90b4714dcc97a0d1647bcc">&#9670;&#160;</a></span>bind()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::UdpSocket::bind </td>
          <td>(</td>
          <td class="paramtype">unsigned short&#160;</td>
          <td class="paramname"><em>port</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;&#160;</td>
          <td class="paramname"><em>address</em> = <code><a class="el" href="classsf_1_1IpAddress.html#a3dbc10b0dc6804cc69e29342f7406907">IpAddress::Any</a></code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Bind the socket to a specific port. </p>
<p>Binding the socket to a port is necessary for being able to receive data on that port.</p>
<p>When providing <a class="el" href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19" title="Special value that tells the system to pick any available port.">sf::Socket::AnyPort</a> as port, the listener will request an available port from the system. The chosen port can be retrieved by calling <a class="el" href="classsf_1_1UdpSocket.html#a5c03644b3da34bb763bce93e758c938e" title="Get the port to which the socket is bound locally.">getLocalPort()</a>.</p>
<p>Since the socket can only be bound to a single port at any given moment, if it is already bound when this function is called, it will be unbound from the previous port before being bound to the new one.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">port</td><td>Port to bind the socket to </td></tr>
    <tr><td class="paramname">address</td><td>Address of the interface to bind to</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#a2c4abb8102a1bd31f51fcfe7f15427a3" title="Unbind the socket from the local port to which it is bound.">unbind</a>, <a class="el" href="classsf_1_1UdpSocket.html#a5c03644b3da34bb763bce93e758c938e" title="Get the port to which the socket is bound locally.">getLocalPort</a> </dd></dl>

</div>
</div>
<a id="a71f2f5c2aa99e01cafe824fee4c573be" name="a71f2f5c2aa99e01cafe824fee4c573be"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a71f2f5c2aa99e01cafe824fee4c573be">&#9670;&#160;</a></span>close()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::close </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Close the socket gracefully. </p>
<p>This function can only be accessed by derived classes. </p>

</div>
</div>
<a id="aafbe140f4b1921e0d19e88cf7a61dcbc" name="aafbe140f4b1921e0d19e88cf7a61dcbc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aafbe140f4b1921e0d19e88cf7a61dcbc">&#9670;&#160;</a></span>create() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::create </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Create the internal representation of the socket. </p>
<p>This function can only be accessed by derived classes. </p>

</div>
</div>
<a id="af1dd898f7aa3ead7ff7b2d1c20e97781" name="af1dd898f7aa3ead7ff7b2d1c20e97781"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af1dd898f7aa3ead7ff7b2d1c20e97781">&#9670;&#160;</a></span>create() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::create </td>
          <td>(</td>
          <td class="paramtype">SocketHandle&#160;</td>
          <td class="paramname"><em>handle</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Create the internal representation of the socket from a socket handle. </p>
<p>This function can only be accessed by derived classes.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">handle</td><td>OS-specific handle of the socket to wrap </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a675457784284ae2f5640bbbe16729393" name="a675457784284ae2f5640bbbe16729393"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a675457784284ae2f5640bbbe16729393">&#9670;&#160;</a></span>getHandle()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">SocketHandle sf::Socket::getHandle </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Return the internal handle of the socket. </p>
<p>The returned handle may be invalid if the socket was not created yet (or already destroyed). This function can only be accessed by derived classes.</p>
<dl class="section return"><dt>Returns</dt><dd>The internal (OS-specific) handle of the socket </dd></dl>

</div>
</div>
<a id="a5c03644b3da34bb763bce93e758c938e" name="a5c03644b3da34bb763bce93e758c938e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5c03644b3da34bb763bce93e758c938e">&#9670;&#160;</a></span>getLocalPort()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned short sf::UdpSocket::getLocalPort </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the port to which the socket is bound locally. </p>
<p>If the socket is not bound to a port, this function returns 0.</p>
<dl class="section return"><dt>Returns</dt><dd>Port to which the socket is bound</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc" title="Bind the socket to a specific port.">bind</a> </dd></dl>

</div>
</div>
<a id="ab1ceca9ac114b8baeeda3b34a0aca468" name="ab1ceca9ac114b8baeeda3b34a0aca468"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab1ceca9ac114b8baeeda3b34a0aca468">&#9670;&#160;</a></span>isBlocking()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">bool sf::Socket::isBlocking </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Tell whether the socket is in blocking or non-blocking mode. </p>
<dl class="section return"><dt>Returns</dt><dd>True if the socket is blocking, false otherwise</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html#a165fc1423e281ea2714c70303d3a9782" title="Set the blocking state of the socket.">setBlocking</a> </dd></dl>

</div>
</div>
<a id="afdd5c655d00c96222d5b477fc057a22b" name="afdd5c655d00c96222d5b477fc057a22b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#afdd5c655d00c96222d5b477fc057a22b">&#9670;&#160;</a></span>receive() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::UdpSocket::receive </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;&#160;</td>
          <td class="paramname"><em>packet</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;&#160;</td>
          <td class="paramname"><em>remoteAddress</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned short &amp;&#160;</td>
          <td class="paramname"><em>remotePort</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Receive a formatted packet of data from a remote peer. </p>
<p>In blocking mode, this function will wait until the whole packet has been received.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">packet</td><td><a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">Packet</a> to fill with the received data </td></tr>
    <tr><td class="paramname">remoteAddress</td><td>Address of the peer that sent the data </td></tr>
    <tr><td class="paramname">remotePort</td><td>Port of the peer that sent the data</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#a664ab8f26f37c21cc4de1b847c2efcca" title="Send raw data to a remote peer.">send</a> </dd></dl>

</div>
</div>
<a id="ade9ca0f7ed7919136917b0b997a9833a" name="ade9ca0f7ed7919136917b0b997a9833a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ade9ca0f7ed7919136917b0b997a9833a">&#9670;&#160;</a></span>receive() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::UdpSocket::receive </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t &amp;&#160;</td>
          <td class="paramname"><em>received</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;&#160;</td>
          <td class="paramname"><em>remoteAddress</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned short &amp;&#160;</td>
          <td class="paramname"><em>remotePort</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Receive raw data from a remote peer. </p>
<p>In blocking mode, this function will wait until some bytes are actually received. Be careful to use a buffer which is large enough for the data that you intend to receive, if it is too small then an error will be returned and <em>all</em> the data will be lost.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the array to fill with the received bytes </td></tr>
    <tr><td class="paramname">size</td><td>Maximum number of bytes that can be received </td></tr>
    <tr><td class="paramname">received</td><td>This variable is filled with the actual number of bytes received </td></tr>
    <tr><td class="paramname">remoteAddress</td><td>Address of the peer that sent the data </td></tr>
    <tr><td class="paramname">remotePort</td><td>Port of the peer that sent the data</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#a664ab8f26f37c21cc4de1b847c2efcca" title="Send raw data to a remote peer.">send</a> </dd></dl>

</div>
</div>
<a id="a664ab8f26f37c21cc4de1b847c2efcca" name="a664ab8f26f37c21cc4de1b847c2efcca"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a664ab8f26f37c21cc4de1b847c2efcca">&#9670;&#160;</a></span>send() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::UdpSocket::send </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;&#160;</td>
          <td class="paramname"><em>remoteAddress</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned short&#160;</td>
          <td class="paramname"><em>remotePort</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Send raw data to a remote peer. </p>
<p>Make sure that <em>size</em> is not greater than <a class="el" href="classsf_1_1UdpSocket.html#a8ad087820b1ae07267858212f3d0fac5a728a7d33027bee0d65f70f964dd9c9eb" title="The maximum number of bytes that can be sent in a single UDP datagram.">UdpSocket::MaxDatagramSize</a>, otherwise this function will fail and no data will be sent.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the sequence of bytes to send </td></tr>
    <tr><td class="paramname">size</td><td>Number of bytes to send </td></tr>
    <tr><td class="paramname">remoteAddress</td><td>Address of the receiver </td></tr>
    <tr><td class="paramname">remotePort</td><td>Port of the receiver to send the data to</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#ade9ca0f7ed7919136917b0b997a9833a" title="Receive raw data from a remote peer.">receive</a> </dd></dl>

</div>
</div>
<a id="a48969a62c80d40fd74293a740798e435" name="a48969a62c80d40fd74293a740798e435"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a48969a62c80d40fd74293a740798e435">&#9670;&#160;</a></span>send() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::UdpSocket::send </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;&#160;</td>
          <td class="paramname"><em>packet</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;&#160;</td>
          <td class="paramname"><em>remoteAddress</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned short&#160;</td>
          <td class="paramname"><em>remotePort</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Send a formatted packet of data to a remote peer. </p>
<p>Make sure that the packet size is not greater than <a class="el" href="classsf_1_1UdpSocket.html#a8ad087820b1ae07267858212f3d0fac5a728a7d33027bee0d65f70f964dd9c9eb" title="The maximum number of bytes that can be sent in a single UDP datagram.">UdpSocket::MaxDatagramSize</a>, otherwise this function will fail and no data will be sent.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">packet</td><td><a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">Packet</a> to send </td></tr>
    <tr><td class="paramname">remoteAddress</td><td>Address of the receiver </td></tr>
    <tr><td class="paramname">remotePort</td><td>Port of the receiver to send the data to</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#ade9ca0f7ed7919136917b0b997a9833a" title="Receive raw data from a remote peer.">receive</a> </dd></dl>

</div>
</div>
<a id="a165fc1423e281ea2714c70303d3a9782" name="a165fc1423e281ea2714c70303d3a9782"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a165fc1423e281ea2714c70303d3a9782">&#9670;&#160;</a></span>setBlocking()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::setBlocking </td>
          <td>(</td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>blocking</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Set the blocking state of the socket. </p>
<p>In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">blocking</td><td>True to set the socket as blocking, false for non-blocking</td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html#ab1ceca9ac114b8baeeda3b34a0aca468" title="Tell whether the socket is in blocking or non-blocking mode.">isBlocking</a> </dd></dl>

</div>
</div>
<a id="a2c4abb8102a1bd31f51fcfe7f15427a3" name="a2c4abb8102a1bd31f51fcfe7f15427a3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2c4abb8102a1bd31f51fcfe7f15427a3">&#9670;&#160;</a></span>unbind()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sf::UdpSocket::unbind </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Unbind the socket from the local port to which it is bound. </p>
<p>The port that the socket was previously bound to is immediately made available to the operating system after this function is called. This means that a subsequent call to <a class="el" href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc" title="Bind the socket to a specific port.">bind()</a> will be able to re-bind the port if no other process has done so in the mean time. If the socket is not bound to a port, this function has no effect.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1UdpSocket.html#ad764c3d06d90b4714dcc97a0d1647bcc" title="Bind the socket to a specific port.">bind</a> </dd></dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="UdpSocket_8hpp_source.html">UdpSocket.hpp</a></li>
</ul>
</div><!-- contents -->
        </div>
        <div id="footer-container">
            <div id="footer">
                SFML is licensed under the terms and conditions of the <a href="https://www.sfml-dev.org/license.php">zlib/png license</a>.<br>
                Copyright &copy; Laurent Gomila &nbsp;::&nbsp;
                Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> &nbsp;::&nbsp;
            </div>
        </div>
    </body>
</html>
